import java.io.*;
import java.net.*;
import java.util.ArrayList;
public class RECEVER extends Thread{
	
	Socket ssoc1,ssoc2 ;	
	ServerSocket ss ;
	ArrayList<USER> userlist = new ArrayList<USER>();
	RECEVER(ServerSocket ss){
		this.ss=ss;
	}
	
	public void recever1() throws IOException{
		int i=0;
		while(true){
			USER newuser = new USER();
			
			ssoc1=ss.accept();
			newuser.mem_socket=ssoc1;
			userlist.add(newuser);
			
			BufferedReader sbr1 = new BufferedReader(new InputStreamReader(ssoc1.getInputStream()));
			String reading1 = sbr1.readLine(); 
			userlist.get(i).mem_ID = reading1;
			userlist.get(i).mem_IP = ss.getInetAddress();
			PrintWriter cpw = new PrintWriter(ssoc1.getOutputStream(),true);
			cpw.println(userlist.get(i).mem_ID+ " connecting success\n");
			//cpw.println();
			i++;
			
			System.out.println("User \""+reading1+"\" connected in server");}
		}
	
	public void recever2() throws IOException{
		while(true){
				InputStream in = ssoc2.getInputStream();
				DataInputStream dts  = new DataInputStream(in);
				//BufferedReader sbr2 = new BufferedReader(new InputStreamReader(ssoc2.getInputStream()));
				String reading2 = dts.readUTF();
				System.out.println(reading2);
			
		}
	}
	
	public void run(){
		
		try {
			recever1();
			recever2();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
